package mapper;

import org.apache.ibatis.annotations.*;
import pojo.Brand;

import java.util.List;

/*
 *操作数据库的Mapper接口
 */
public interface BrandMapper {
    //查询所有品牌（基本开发完毕）
    @ResultMap("brandResultMap") //映射
    @Select("select * from t_brand")
    List<Brand> selectAll();

    //单个查询
    @ResultMap("brandResultMap")
    @Select("select * from t_brand where id = #{id}")
    Brand selectBuId(int id);

    //插入一个品牌的方法
    @Insert("insert into t_brand values" +
            "(null,#{brandName},#{companyName},#{ordered},#{description},#{status})")
    void add(Brand brand);

    //修改一个品牌
    @Update("update t_brand set brand_name=#{brandName}," +
            "company_name=#{companyName}, ordered=#{ordered}," +
            "description=#{description},status=#{status} where id=#{id}")
    void update(Brand brand);

    //删除一个品牌
    @Delete("DELETE FROM t_brand WHERE id = #{id}")
    void deleteById(int id);

    //以下是分页查询
    //1.查询某一页的数据
    @ResultMap("brandResultMap")
    @Select("select * from t_brand limit #{beginIndex},#{pageSize}")
    List<Brand> selectAllPage(@Param("beginIndex") int beginIndex,
                              @Param("pageSize") int pageSize);

    //2.查询总的数据条数
    @Select("select count(1) from t_brand")
    int selectCount();
}


